<!DOCTYPE html>
<html>
  <head>
    <title>ajax01.html</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <script type="text/javascript">
    	/*获取Ajax对象*/
    	function getXhr(){
    		var xhr=null;
    		//确保IE7，IE8，FireFox下可以运行
    		if(window.XMLHttpRequest){
    			xhr=new XMLHttpRequest();
    		}else{
    			//确保IE6可以运行，无视更古老的IE浏览器
    			xhr=new ActiveXObject("Microsoft.XMLHttp");
    		}
    		return xhr;
    		/**
    		 *更简易的写法
    		 *xhr=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHttp");
    		 */
    	}
    </script>
  </head>
  
  <body>
  		<!-- 获取XMLHttpRequest对象 -->
    	<a href="javascript:;" onclick="alert(getXhr());">获取Ajax对象</a>
  </body>
</html>
